<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$install = check_account_permission('jy_merch');
if(empty($install)){
	exi('请联系管理员开启<多商户>！','error','goback');
}
if($_RQ['op']=='main'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 20;
	if($_RQ['num']){
		$psize=$_RQ['num'];
	}
	$total='';
	$params=array(
		'uniacid'=>$_SESSION['uniacid'],
		'mid'=>$_SESSION['uid'],
		'merchid >'=>0,
	);
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),
		'fields'=>$fields,
		'orderby'=>$orderby,
	);
	$listlog=model('jy_weishop/merch')->get($parameter,$total);
	foreach($listlog as &$item){
		$merchinfo=pdo_get('jy_merch_user',array('id'=>$item['merchid']));
		$item['logo']=tomedia($merchinfo['logo']);
		if(empty($item['logo'])){
			$item['logo']=pdo_getcolumn('core_members',array('id'=>$merchinfo['mid'],'uniacid'=>$_SESSION['uniacid']),'avatar');
			$item['logo']=$item['logo']?tomedia($item['logo']):'';
		}
		$item['title']=$merchinfo['merchname'];
	}
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$return['listlog']=$listlog;
	exi($return);
}
if($_RQ['op']=='list'){
	$total='';
	$params=array(
		'uniacid'=>$_SESSION['uniacid'],
		'address <>'=>'',
	);
	if($_RQ['keyword']){
		if(is_numeric($_RQ['keyword'])){
			$params['id']=intval($_RQ['keyword']);
			$return['params']['id']=intval($_RQ['keyword']);
		}else{
			$params['merchname like']='%'.$_RQ['keyword'].'%';
			$return['params']['keyword']=$_RQ['keyword'];
		}
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 50;
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),
		'fields'=>$fields,
		'orderby'=>$orderby,
	);
	$lat_lng=array('lat'=>$_RQ['lat'],'lng'=>$_RQ['lng']);
	$list=model('jy_merch/model')->get($parameter,$total,$lat_lng);
	foreach($list as &$item){
		if(empty($item['logo'])){
			$item['logo']=pdo_getcolumn('core_members',array('id'=>$item['mid'],'uniacid'=>$_SESSION['uniacid']),'avatar');
			$item['logo']=$item['logo']?tomedia($item['logo']):'';
		}
	}
	$return['list']=$list;
	exi($return);
}